<?php
namespace app\index\controller;

use app\index\model\Method;
use app\index\model\FriendsCircle;
use think\Controller;
use think\Db;


class Index extends Controller
{
    public function index()
    {
        //获取banner信息
        $bannerWhere = [
            'is_del' => 0,
            'is_display' => 0
        ];
        $banner = Db::name('banner_pc')->order('banner_sort desc')->where($bannerWhere)->select();

        //获取精选景点封面
        $tourWhere = [
            'is_del' => 0,
            'is_display'=>0,
            'is_tuijian' =>1
        ];
        $tour = Db::name('tours')->field('tour_id,tour_covers')->order('sort','desc')->limit(0,5)->where($tourWhere)->select();

        //获取友圈标签
        $frinds_circle_tag = Db::name('fc_tags')->field('id,data_name')->where('is_display',0)->order("data_sort","desc")->select();

        //获取精选攻略
        $methodWhere = [
            't1.is_del' => 0,
            't1.is_pass'=>1,
            't1.is_select'=>1
        ];
        $methodField = ['t1.mid,t1.title,t1.image,t1.create_time,t2.nickname'];
        $methodObj = Method::getMethodList($methodField,$methodWhere,1,9);
        $method = [];
        foreach ($methodObj as $k => $v){

            $method[$k]['id'] = $v['mid'];
            $method[$k]['title'] = $v['title'];
            $imageArr = explode(',',$v['image']);
            $method[$k]['image'] = $imageArr[0];
            $method[$k]['create_time'] = substr(time_ago($v['create_time']),0,10);
            $method[$k]['nickname'] = $v['nickname'];
            $method[$k]['kinds'] = 1;

        }

        //获取精选跟团游
        $groupTour = Db::name('group_tour')
            ->field('id,gtour_title,gtour_covers,gtour_days,gtour_price,sale_sum')
            ->where('is_del',0)
            ->where('is_display',0)
            ->page(0,6)
            ->order('id','desc')
            ->select();


        $this->assign('frinds_circle_tag',$frinds_circle_tag);
        $this->assign('groupTour',$groupTour);
        $this->assign('method',$method);
        $this->assign('tour',$tour);
        $this->assign('banner',$banner);
        return view();
    }

    public function getTuijianTour(){

        if (request()->isAjax()){

            //获取精选景点封面
            $tourWhere = [
                'is_del' => 0,
                'is_display'=>0,
                'is_tuijian' =>1
            ];
            $tour = Db::name('tours')
                ->field('tour_id as id,tour_covers as path')
                ->limit(0,5)
                ->where($tourWhere)
                ->order("sort","desc")
                ->select();

            return $tour;

        }

    }

    public function getTuijianRestaurant(){

        if (request()->isAjax()){

            //获取精选景点封面
            $foodWhere = [
                'is_del' => 0,
                'is_pass'=>1,
                'is_tuijian' =>1
            ];
            $food = Db::name('food_store')
                ->field('food_store_id as id,food_store_cover as path')
                ->limit(0,5)
                ->order("sort","desc")
                ->where($foodWhere)
                ->select();

            return $food;

        }

    }

    public function getTuijianHotel(){

        if (request()->isAjax()){

            //获取精选景点封面
            $hotelWhere = [
                'is_del' => 0,
                'is_pass'=>1,
                'is_tuijian' =>1
            ];
            $hotel = Db::name('hotel')
                ->field('hotel_id as id,hotel_covers as path')
                ->limit(0,5)
                ->order("sort","desc")
                ->where($hotelWhere)
                ->select();

            return $hotel;

        }

    }

    public function getMethod(){

        if (request()->isAjax()){

            //获取精选攻略
            $methodWhere = [
                't1.is_del' => 0,
                't1.is_pass'=>1,
                't1.is_select'=>1
            ];
            $methodField = ['t1.mid,t1.title,t1.image,t1.create_time,t2.nickname'];
            $methodObj = Method::getMethodList($methodField,$methodWhere,1,9);

            $method = [];
            foreach ($methodObj as $k => $v){

                $method[$k]['id'] = $v['mid'];
                $method[$k]['title'] = $v['title'];
                $imageArr = explode(',',$v['image']);
                $method[$k]['image'] = $imageArr[0];
                $method[$k]['create_time'] = substr(time_ago($v['create_time']),0,10);
                $method[$k]['nickname'] = $v['nickname'];
                $method[$k]['kinds'] = 1;

            }

            return $method;

        }

    }

    public function getFriendCircle(){

        if (request()->isAjax()){

            $param = request()->param();

            //获取精选圈子
            $circleWhere = [
                't1.is_del'     => 0,
                't1.is_pass'    => 1,
                't1.fc_id'      => $param['fc_id']
            ];
            $circleField = ['t1.f_id,t1.fc_title,t1.image,t1.create_time,t1.status,t2.nickname'];

            $circleObj =FriendsCircle::getCircleList($circleField,$circleWhere,1,9);

            $circle = [];
            foreach ($circleObj as $k => $v){

                $circle[$k]['id'] = $v['f_id'];
                $circle[$k]['title'] = $v['fc_title'];
                $imageArr = explode(',',$v['image']);
                $circle[$k]['image'] = $imageArr[0];
                $circle[$k]['create_time'] = substr(time_ago($v['create_time']),0,10);
                $circle[$k]['nickname'] = $v['nickname'];
                $circle[$k]['kinds'] = $v['status'];

            }

            return $circle;

        }

    }

    public function loginout(){

        session(null);

        return ['code'=>1];

    }

}
